#!/bin/bash

git pull origin master

#rm -f src/main/resources/application.properties
#cp ./application.properties src/main/resources/

mvn clean package -Dmaven.test.skip=true -Preal

TAR=target

DIR=/fafa/app/sys-bawangcan
JARFILE=sys-bawangcan.jar
echo "关闭应用...."
ps -fe |grep $JARFILE |awk 'NR==1{print $2}'| xargs kill -9

echo "备份应用文件...."

if [ ! -d $DIR/backup ];then
   mkdir -p $DIR/backup
fi

cd $DIR

mv $JARFILE backup/$JARFILE$DATE

echo "拷贝应用文件...."
mv -f /fafa/xm/sys-bawangcan/target/$JARFILE  .

find /tmp -name 'tomcat.*' -type d -mmin +60|xargs rm -fr

echo "启用应用...."
nohup java -jar $JARFILE  >./admin.log 2>&1 &

if [ $? = 0 ];then
        sleep 20
        tail -n 50 ./admin.log
fi

echo "删除过期备份...."
cd backup/
ls -lt|awk 'NR>5{print $NF}'|xargs rm -rf

echo "启动成功OK"
